import { getDataList,getThisList,getDiscuss,saveDiscuss } from "../api/msbd";
import { stat } from "fs";

const msbd = {
    namespaced: true,
    state: {
        list: [],
        total: 0,
        pageObj: {
            pages: 0,
            pagesize: 20
        },
        items:{},
        discussArr:[],
        currentPage:0
    },
    getters: {},
    mutations: {
        setCurrentPage(state, pos) {
            state.currentPage = pos
        },
        setList(state, res) {
            state.list = state.list.concat(res.data)
            state.total = res.total
        },
        setPage(state) {
            state.pageObj.pages += 1
        },
        clearList(state) {
            state.list = []
            state.pageObj.pages=0
        },
        setItem(state,res){
            state.items=res.data
        },
      setdiscussArr(state,discussArr){
          state.discussArr=discussArr
          console.log(state.discussArr)
      }
    },
    actions: {
        async saveDis({commit},obj){
            console.log(obj)
            let {data}=await saveDiscuss(obj)
            console.log(data)
           // commit('setdiscussArr',data.data)
        },
        async getDisList({commit},bdid){
            let {data}=await getDiscuss(bdid)
            console.log(data)
            commit('setdiscussArr',data.data)
        },
        async getItem({commit},id){
            let {data}=await getThisList({id})
            commit('setItem',data)
        },
        clearFn({ commit }) {
            commit('clearList')
        },
        async getList({ commit, state }) {
            let { data } = await getDataList(state.pageObj)
            commit('setList', data)
            commit('setPage')
        }
    },
}
export default msbd